//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "ForwardRateStructure.h"
using namespace Cephei::QL::Termstructures::Yield;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/InterestRate.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (boost::shared_ptr<QuantLib::ForwardRateStructure>& childNative, Object^ owner) : CYieldTermStructure(CForwardRateStructure::typeid)
{
#ifdef HANDLE
	_phForwardRateStructure = NULL;
#endif
	_ppForwardRateStructure = &childNative;
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
}
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (QuantLib::ForwardRateStructure& childNative, Object^ owner) : CYieldTermStructure(CForwardRateStructure::typeid)
{
#ifdef HANDLE
	_phForwardRateStructure = NULL;
#endif
	_ppForwardRateStructure = new boost::shared_ptr<QuantLib::ForwardRateStructure> (&childNative);
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
    _ForwardRateStructureOwner = owner;
    _YieldTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (CForwardRateStructure^ copy) : CYieldTermStructure(CForwardRateStructure::typeid)
{
#ifdef HANDLE
	_phForwardRateStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppForwardRateStructure = new boost::shared_ptr<QuantLib::ForwardRateStructure> (copy->GetShared());
        _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
    }
}
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (PLATFORM::Type^ t) : CYieldTermStructure(CForwardRateStructure::typeid)
{
#ifdef HANDLE
	_phForwardRateStructure = NULL;
#endif
	if (!t->IsSubclassOf(CForwardRateStructure::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (QuantLib::Handle<QuantLib::ForwardRateStructure>& childNative, Object^ owner)  : CYieldTermStructure(CForwardRateStructure::typeid)
{
	_phForwardRateStructure = &childNative;
	_ppForwardRateStructure = &static_cast<boost::shared_ptr<QuantLib::ForwardRateStructure>>(childNative.currentLink());
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
    _ForwardRateStructureOwner = owner;
}
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (QuantLib::Handle<QuantLib::ForwardRateStructure> childNative)  : CYieldTermStructure(CForwardRateStructure::typeid)
{
	_phForwardRateStructure = &childNative;
	_ppForwardRateStructure = &static_cast<boost::shared_ptr<QuantLib::ForwardRateStructure>>(childNative.currentLink());
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Yield::CForwardRateStructure::CForwardRateStructure (QuantLib::ForwardRateStructure childNative)  : CYieldTermStructure(CForwardRateStructure::typeid)
{
#ifdef HANDLE
	_phForwardRateStructure = NULL;
#endif
	_ppForwardRateStructure = new boost::shared_ptr<QuantLib::ForwardRateStructure> (new QuantLib::ForwardRateStructure (childNative));
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppForwardRateStructure));
}
#endif

Cephei::QL::Termstructures::Yield::CForwardRateStructure::~CForwardRateStructure ()
{
    if (_ppForwardRateStructure != NULL)
    {
	    delete _ppForwardRateStructure;
        _ppForwardRateStructure = NULL;
    }
}
Cephei::QL::Termstructures::Yield::CForwardRateStructure::!CForwardRateStructure ()
{
    if (_ppForwardRateStructure != NULL)
    {
	    delete _ppForwardRateStructure;
    }
}
QuantLib::ForwardRateStructure& Cephei::QL::Termstructures::Yield::CForwardRateStructure::GetReference ()
{
    if (_ppForwardRateStructure == NULL) throw REFNEW NativeNullException ();
	return **_ppForwardRateStructure;
}
boost::shared_ptr<QuantLib::ForwardRateStructure>& Cephei::QL::Termstructures::Yield::CForwardRateStructure::GetShared ()
{
    if (_ppForwardRateStructure == NULL) throw REFNEW NativeNullException ();
	return *_ppForwardRateStructure;
}
QuantLib::ForwardRateStructure* Cephei::QL::Termstructures::Yield::CForwardRateStructure::GetPointer ()
{
    if (_ppForwardRateStructure == NULL) throw REFNEW NativeNullException ();
	return &**_ppForwardRateStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ForwardRateStructure>& Cephei::QL::Termstructures::Yield::CForwardRateStructure::GetHandle ()
{
	if (_phForwardRateStructure == NULL)
	{
		_phForwardRateStructure = new Handle<QuantLib::ForwardRateStructure> (*_ppForwardRateStructure);
	}
	return *_phForwardRateStructure;
}
#endif
bool Cephei::QL::Termstructures::Yield::CForwardRateStructure::HasNative () 
{
	return (_ppForwardRateStructure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

